package com.hunan.api.catv.mq.consumer;


import com.google.gson.JsonObject;
import com.hunan.api.catv.entity.ServiceResult;
import com.hunan.api.catv.mq.MqConstants;
import com.hunan.api.catv.service.biz.activity.ActivityVideoBiz;
import com.hunan.api.catv.utils.GsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class ActivityUploadConsumer {

    public static Logger log = LoggerFactory.getLogger(ActivityUploadConsumer.class);


    @Autowired
    ActivityVideoBiz activityVideoBiz;

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = MqConstants.activity_upload_queue, durable = "true"), exchange = @Exchange(value = MqConstants.activity_upload_exchange, durable = "true", type = "topic"), key = MqConstants.activity_upload_routingkey))
    public void submit(String msg) {
        try {
            JsonObject msgJson = GsonUtils.fromJson(msg, JsonObject.class);
            Integer activityId = msgJson.get("activityId").getAsInt();
            Integer memberId = msgJson.get("memberId").getAsInt();
            String fileId = msgJson.get("fileId").getAsString();
            ServiceResult addResult = activityVideoBiz.add(activityId, memberId, fileId, "");
            if (!addResult.getStatus()) {
                log.error("[活动视频添加失败]" + addResult);
                return;
            }
        } catch (Exception e) {
            log.error("[活动视频添加失败]:{}", e);
        }

    }
}
